$(function(){
    $.ajax({
        url:'http://localhost:3000/play/new',
        method:'GET',
        success:function(res){
            var str = '';
            $.each(res,function(index,item){                   
                $.each(item,function(i,item1){
                    str += "<li>"+
                    "<img class=img src="+item1.img+">"+
                    "<p class=p>"+item1.text+"</p>"+
                    "<span class=span>"+item1.description+"</span>"+
                    "<div class=left>"+item1.price+"</div>"+
                    "<div class=right>"+
                    "<img src=../css/img/xin.png>"+item1.like+""+
                    "<img src=../css/img/reply.png>"+item1.words+""+
                    "</div>"+
                    "</div>"+
                    "</li>"
                })           
            })
            $('.discover-con').html(str)
        } 
    })

    $.ajax({
        url:'http://localhost:3000/play/hot',
        method:'GET',
        success:function(res1){
            var str1 = '';
            $.each(res1,function(index,item){                   
                $.each(item,function(i,item1){
                    str1 += "<li>"+
                    "<img class=img src="+item1.img+">"+
                    "<p class=p>"+item1.text+"</p>"+
                    "<span class=span>"+item1.description+"</span>"+
                    "<div class=left>"+item1.price+"</div>"+
                    "<div class=right>"+
                    "<img src=../css/img/xin.png>"+item1.like+""+
                    "<img src=../css/img/reply.png>"+item1.words+""+
                    "</div>"+
                    "</div>"+
                    "</li>"
                })           
            })
            $('.discover2-con').html(str1)
        } 
    })

    $.ajax({
        url:'http://localhost:3000/play/category',
        method:'GET',
        success:function(res2){
                var str2 = '';
                console.log(res2);
                $.each(res2,function(index,item){
                    str2 += " <div class=category-con>"+
                    "<div class=cate-title>"+
                    "<p>"+item.title+"</p>"+
                    "</div>";
                for(var i = 0; i < 5; i ++){
                    str2 += "<div class=cate-icon>"+
                    "<img src=../img/cat_"+(i+1)+".png>"+
                    "<div>"+item.list[i].productName+"("+item.list[i].nums+")"+"</div>"+
                    "</div>"
                }
               str2 += "<div class=cate-list>"+
               "<hr style=border:none;border-top:1px;border-style:dashed;border-color:#b4b0b0;/>"+
               "<ul>";
                for(var i = 0; i < item.list.length; i ++){
                    str2 +=
                        "<li>"+item.list[i].productName+"("+item.list[i].nums+")"+"</li>"
                }
                str2 +=  " </ul>"+
                "</div>"+
                "</div>"
                })
                $('.category-box').html(str2)
        }

    })

    $(".tab_list li").click(function(){
        $(this).addClass('list-con').siblings('li').removeClass('list-con');
        var index = $(this).index();
        $(".tab_con .item").eq(index).show().siblings('.item').hide();
    })
    $('.more').click(function(){
        $('.discover, .discover2').css('height','2190px')
        $(this).html('没有更多啦~').css('color','gray')
    })
})